<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category FileCategory.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/7/16  16:01
 * +--------------------------------------------------------+
 */

namespace App\Models;


class FileCategory extends BaseModel
{
    protected $table = "file_category";

    static public function getAll($name)
    {
        $query = self::query();
        if($name) $query = $query->where('name','like',"%$name%");
        $data = $query->get();
        $list = self::tidyMenuTier($data->toArray());

        return return_success_msg('数据请求成功', $list);

    }

    static public function tidyMenuTier($menusList,$pid = 0,$navList = [])
    {

        foreach ($menusList as $k=>$menu){
            if($menu['pid'] == $pid){
                unset($menusList[$k]);
                $menu['child'] = self::tidyMenuTier($menusList,$menu['id']);
                $navList[] = $menu;
            }
        }
        return $navList;
    }

}
